package com.ck.scan.proxy;

import com.ck.scan.annotation.CkInterfaceAnnotation;
import com.ck.scan.annotation.CkMethodAnnotation;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * TODO
 *
 * @author chenke
 * @version 1.0
 * @date 2021-12-22 15:19
 */
public class CkInterfaceProxy<T> implements InvocationHandler, Serializable {

    private final Class<T> ckInterface;

    public CkInterfaceProxy(Class<T> ckInterface) {
        this.ckInterface = ckInterface;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (this.ckInterface.isAnnotationPresent(CkInterfaceAnnotation.class)) {
            // 读取类上注解
            CkInterfaceAnnotation interfaceAnnotation = this.ckInterface.getAnnotation(CkInterfaceAnnotation.class);
            System.out.println("调用接口类名:" + interfaceAnnotation.value());
            if (method.isAnnotationPresent(CkMethodAnnotation.class)) {
                // 读取方法上注解
                CkMethodAnnotation methodAnnotation = method.getAnnotation(CkMethodAnnotation.class);
                System.out.println("调用接口方法名:" + methodAnnotation.value());
            }
        }

        return null;
    }
}

